package easy.trace.wrapper;


import easy.trace.Span;
import easy.trace.agent.Tracer;

public class TraceRunnable implements Runnable {
    private final Span parent;
    private final Runnable runnable;
    private Tracer tracer = Tracer.getTracer();

    public TraceRunnable(Runnable r) {
        this.parent = this.tracer.getParentSpan();
        this.runnable = r;
    }

    public TraceRunnable(Runnable r, Span p) {
        this.runnable = r;
        this.parent = p;
    }

    @Override
    public void run() {
        if (this.parent != null) {
            this.tracer.setParentSpan(this.parent);
        }

        this.runnable.run();
    }
}

